package com.example.security.exception;

import com.example.security.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器.
 *
 * @author linzp
 * @date 2022/2/11 15:35
 */
@Slf4j
@Component
@RestControllerAdvice
public class GlobalExceptionHandle {

    @ExceptionHandler(Exception.class)
    public Result<String> commonExceptionHandle(Exception exception) {
        log.error(exception.getMessage(), exception);
        return Result.fail(exception.getLocalizedMessage());
    }

}
